package com.youme.section.shop.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.hyphenate.easeim.R
import com.salton123.app.BaseApplication
import com.youme.model.Room
import com.youme.section.shop.AddCaiListenerr
import kotlinx.android.synthetic.main.item_shop_details_menu_right.view.*

/**
 * PackageName : com.ziwenl.meituandemo.ui.store.adapter
 * Author : Ziwen Lan
 * Date : 2020/9/11
 * Time : 16:26
 * Introduction :
 */
class MenuRightForBaoxiangAdapter(private val data: MutableList<Room>) :
    RecyclerView.Adapter<MenuRightForBaoxiangAdapter.MyViewHolder>() {

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)

    private lateinit var addCaiListenerr: AddCaiListenerr
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_shop_details_menu_rightforbaoxiang, parent, false)
        return MyViewHolder(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    public fun setAddListener(listenerr: AddCaiListenerr) {
        addCaiListenerr = listenerr
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val textpos = data[position]
        holder.itemView.view_bottom.visibility = if (position == data.size - 1) {
            View.VISIBLE
        } else {
            View.GONE
        }
        holder.itemView.iv_add_shopping_cart.setOnClickListener {
//            addCaiListenerr.addCai()
        }
        Glide.with(BaseApplication.sInstance)
            .load(textpos.deskPic).into(holder.iv_goods)
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val iv_goods: ImageView = itemView.findViewById(R.id.iv_goods)
        val tv_goods_name: TextView = itemView.findViewById(R.id.tv_goods_name)
        val tv_sku: TextView = itemView.findViewById(R.id.tv_sku)
        val tv_goods_price_unit: TextView = itemView.findViewById(R.id.tv_goods_price_unit)
        val tv_goods_price: TextView = itemView.findViewById(R.id.tv_goods_price)
        val iv_add_shopping_cart: ImageView = itemView.findViewById(R.id.iv_add_shopping_cart)
    }
}